﻿using System;

namespace Mojo.Widgets
{
    /// <summary>
    /// &lt;div x-mojo-element="TextField" id="textFieldId" class="textFieldClass" name="textFieldName"&gt;&lt;/div&gt;
    /// </summary>
    public class TextField
    {
        /// <summary>
        /// Focuses the input part of the text field.
        /// </summary>
        public void Focus()
        {
        }

        /// <summary>
        /// Blurs the input part of the text field.
        /// </summary>
        public void Blur()
        {
        }

        /// <summary>
        /// Gets the plaintext value of the text field.
        /// </summary>
        /// <returns></returns>
        public string GetValue()
        {
            return null;
        }

        /// <summary>
        /// Sets the plaintext value of the text field.
        /// </summary>
        /// <param name="val"></param>
        public void SetValue(string val)
        {
        }
        
        /// <summary>
        /// Returns an Selection object that describes the position of the cursor; if start is not equal to end, then there is text selected.
        /// </summary>
        /// <returns></returns>
        public Selection GetCursorPosition()
        {
            return null;
        }

        /// <summary>
        /// Sets the cursor position in the input portion of the TextField; 
        /// if start and end are not the same, then this will select the text between START and END; 
        /// if start and/or end occur in invalid positions, they will be changed to valid positions at the end of the text if they were larger than the size of the value, or at the beginning, if they are smaller than the size of the value; empty text will result in a cursor at the start of the TextField.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public void SetCursorPosition(int start, int end)
        {
        }
    }

    public class Selection
    {        
        public int SelectionStart;
        public int SelectionEnd;
    }

    public class TextFieldAttributes : WidgetsCreateAttributes
    {
        /// <summary>
        /// Optional. Model property name for selector value
        /// </summary>
        public string ModelProperty;

        /// <summary>
        /// Optional. Model property name for disabled boolean
        /// </summary>
        public string DisabledProperty;

        /// <summary>
        /// Optional. Initially displayed string; supplanted by model value if supplied.
        /// </summary>
        public string HintText;

        /// <summary>
        /// Optional. If supplied, the textarea will have this name, so that when it is serialized, the property can be easily pulled out.
        /// </summary>
        public string InputName;

        /// <summary>
        /// Optional. Auto line wrapping to field width
        /// </summary>
        public bool Multiline;
 
        /// <summary>
        /// Optional. Function must return 'true' to allow input character, or 'false' if not allowed; note: this event is sent as a result of a keyPress event, so you must check against key codes matching ASCII characters.
        /// </summary>
        public Func<bool, char> CharsAllow;

        /// <summary>
        /// Optional. If true, field has focus on scene push.
        /// </summary>
        public bool AutoFocus;

        /// <summary>
        /// Optional. initial state of modifier keys for this field. Can be:
        /// Mojo.Widget.shiftLock (shifts all characters typed),
        /// Mojo.Widget.numLock (uses the "Num" character equivalent for all characters typed),
        /// Mojo.Widget.shiftSingle (shifts the first character typed),
        /// Mojo.Widget.numSingle (uses "Num" character equivalent for the first character typed)
        /// </summary>
        public string ModifierState;

        /// <summary>
        /// Optional. Automatically grow field horizontally.
        /// </summary>
        public bool GrowWidth;

        /// <summary>
        /// Optional. Maximum width of field
        /// </summary>
        public int AutoResizeMax;

        /// <summary>
        /// Optional. When used in conjunction with multiline, if this is set, then enter key will submit rather than newline.
        /// </summary>
        public bool EnterSubmits;

        /// <summary>
        /// Optional. Limit height resize (scrolls text rather than grow field).
        /// </summary>
        public bool LimitResize;

        /// <summary>
        /// Optional. There will be no resizing in any dimension.
        /// </summary>
        public bool PreventResize;

        /// <summary>
        /// Optional. If the TextField is disabled, tapping and holding and releasing will enable it; if disabled is not set, this is ignored.
        /// </summary>
        public bool HoldToEnable;

        /// <summary>
        /// Sets the cursor mode when the field gets focus. Options are:
        /// Mojo.Widget.focusSelectMode
        /// Mojo.Widget.focusInsertMode
        /// Mojo.Widget.focusAppendMode
        /// Either text will all be selected (Select), or a cursor will appear where the user tapped (Insert) or the cursor will go to the end of the text (Append).
        /// </summary>
        public string FocusMode;		 

        /// <summary>
        /// Optional. If true, sends a propertyChange event on every character change to a field; otherwise only when focus is lost.
        /// </summary>
        public bool ChangeOnKeyPress;

        /// <summary>
        /// Optional. Maximum character length of field; does not apply to multiline fields where an exception will be thrown.
        /// </summary>
        public int MaxLength;

        /// <summary>
        /// Optional. Enter key required to submit; other navigation will not generate submit event.
        /// </summary>
        public bool RequiresEnterKey;
        
        /// <summary>
        /// Optional. Tap and Hold to focus/edit; Tap only will be ignored.
        /// </summary>
        public bool HoldToEdit;

        /// <summary>
        /// Optional. Enable emoticons on this field.
        /// </summary>
        public bool Emoticons;


        /// <summary>
        /// Optional. Whether to enable the SmartTextEngine services of PalmSysMgr. Enabled by default in the TextField.
        /// </summary>
        public bool AutoReplace;

        /// <summary>
        /// Optional. Use this to change the autocapitalization on the TextField. Options are:
        /// Mojo.Widget.steModeSentenceCase (capitalization like a sentence),
        /// Mojo.Widget.steModeTitleCase (capitalize first letter of each word),
        /// Mojo.Widget.steModeLowerCase (no capitalization)
        /// </summary>
        public string textCase;
    }

    public class TextFieldModel : WidgetsCreateModel
    {
        /// <summary>
        /// Required. Initial and updated value of widget
        /// </summary>
        public string Value;
	 
        /// <summary>
        /// Optional. If true, toggle is inactive.
        /// </summary>
        public bool Disabled;
    }
}
